/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package r.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

/**
 *
 * @author jcrada
 */
public class Script {

    private File file;
    private BufferedWriter writer;

    public Script(File file) {
        this.file = file;
    }

    public void startRecording() throws Exception {
        startRecording(false);
    }
    
    public void startRecording(boolean append) throws Exception {
        this.writer = new BufferedWriter(new FileWriter(file, append));
    }


    public void record(String commands) {
        try {
            this.writer.write(commands);
            this.writer.flush();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    public void stopRecording() throws Exception {
        if (this.writer != null) {
            this.writer.close();
        }
        this.writer = null;
    }

    public boolean isRecording() {
        return this.writer != null;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public BufferedWriter getWriter() {
        return writer;
    }

    public void setWriter(BufferedWriter writer) {
        this.writer = writer;
    }
}
